Before you start, make sure to have the tidyverse
and the tidyquant
packages loaded in your session. Following the instructions from the previous lectures, you can either make a direct call to each package, library(tidyverse)
and library(tidyquant)
, or copy-paste the script from the course’s official website.
- Use
tq_get()
to load information from the S&P Index and the Deadlift ETF constituents in two separate objects. You can use the code ^GSPC
to retrieve information for the index, and you can pass a vector c('ticker1','ticker2',...,'ticker_n')
to get information on the Deadlift ETF constituents
- Filter for observations starting between 2020 (beginning of) and 2024 (end of) using the
from
and to
arguments of the tq_get()
function
- Group the Deadlift ETF data by
symbol
using the group_by()
function
- For both data sets, create a
yearly_ret
variable that calculates the yearly return of a given security. You can use the tq_transmute()
function, passing the yearlyReturn()
function along the chain
- For the Deadlift data set, regroup the data by
date
and calculate the Deadlift returns using a mutate()
function (Hint: it is an equally weighted portfolio)
- Merge both datasets using
inner_join()